package cn.uploading;

import cn.GetPath.accessPath;
import cn.dto.BizConstant;
import cn.hutool.http.HttpRequest;
import cn.utils.AnalysisExcel;
import cn.utils.GuideTable;
import cn.utils.ReadTxt;
import cn.zyh.dto.BasicInformation;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.apache.log4j.Logger;


import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.log4j.Logger;

/**
 * 读取excel文件
 */

public class ExcelApp {
    private static final AtomicInteger deviceCount = new AtomicInteger();
    private static final AtomicInteger failure = new AtomicInteger();

    private static Logger log4j = Logger.getLogger(ExcelApp.class);


    public static void main(String[] args) {


        BizConstant bizConstant = ReadTxt.readFile(accessPath.getTxt());
        String upl_url = bizConstant.getUPL_URL();


        var analysisExcel = new AnalysisExcel();

        ArrayList<BasicInformation> basicInformations = analysisExcel.ToAnalysisExcel(accessPath.getXls());


        basicInformations.forEach(e -> {
            
            String stuString = JSONObject.toJSONString(e);
            System.out.println(stuString);

            String resp = HttpRequest.post("http:" + upl_url + ":8000/api-projectdatamanage/equipmentsync/sync").body("[" + stuString + "]").header("Authenticator", GuideTable.getSessionId(bizConstant)).execute().body();


            JSONObject jsonObject = JSONObject.parseObject(resp);
            Object data1 = jsonObject.get("data");
            Object data = jsonObject.get("code");


            if (data == "500") {
                log4j.info(resp);
                failure.incrementAndGet();
            } else log4j.info(resp);
            deviceCount.incrementAndGet();
        });
        log4j.info("累计上传数量" + "=" + deviceCount);
        log4j.info("失败次数" + failure);


    }
}
